package com.goods.controller.business;



import com.goods.business.service.ProductService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business/product")
public class ProductListController {

    @Autowired
    private ProductService productService;



    //加载物资列表
    @GetMapping("/findProductList")
    public ResponseBean<PageVO> getProductList(
            @RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
            @RequestParam(value = "pageSize",required = false) Integer pageSize,
            @RequestParam(value = "categorys",required = false) String categorys,
            @RequestParam("supplier") String supplier,
            ProductVO productVO
            ) {
        PageVO pageVO =  productService.getProductList(pageNum,pageSize,categorys,supplier,productVO);
       return ResponseBean.success(pageVO);
    }

    //添加物资
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        productService.add(productVO);
        return ResponseBean.success();
    }

    //打开编辑弹窗
    @GetMapping("/edit/{id}")
    public ResponseBean<ProductVO> edit(@PathVariable Long id){
      ProductVO productVO =   productService.edit(id);
        return ResponseBean.success(productVO);
    }

   //修改
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductVO productVO){
        productService.update(id,productVO);
        return ResponseBean.success();
    }

    //移入回收站
   @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
       productService.remove(id);
       return ResponseBean.success();
   }

   //恢复
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        productService.back(id);
        return ResponseBean.success();
    }
   //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        productService.delete(id);
        return ResponseBean.success();
    }

    //通过
/*    async publish(id) {
                const {data: res} = await this.$http.put("business/product/publish/" + id);*/
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        productService.publish(id);
        return ResponseBean.success();
    }

}
